<template>
  <div class="mod-shop-notice">
    <avue-crud ref="crud"
               :page="page"
               :data="dataList"
               :table-loading="dataListLoading"
               :option="tableOption"
               @search-change="searchChange"
               @search-reset="searchReset"
               @on-load="getDataList"
               @refresh-change="refreshChange">
      <template slot-scope="scope" slot="menu">
        <el-button
          icon="el-icon-view"
          size="small"
          type="primary"
          @click="viewNotice(scope.row.id)"
        >{{$t('live.view')}}
        </el-button>
      </template>
      <template slot="search">
        <el-col :md="10" :xs="24">
          <el-form-item
            :label="$t('publics.releaseTime')"
            :label-width="this.$i18n.t('language') === 'language' ? '120px' : '80px'"
          >
            <el-date-picker
              v-model="dateRange"
              type="datetimerange"
              :range-separator="$t('date.tip')"
              value-format="yyyy-MM-dd HH:mm:ss"
              :start-placeholder="$t('date.start')"
              :end-placeholder="$t('date.end')"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </template>
    </avue-crud>
    <el-dialog
      :title="this.$i18n.t('notice.plaNotice')"
      :visible.sync="viewDialog"
      width="30%"
      :before-close="handleClose">
      <p style="text-align: center">{{dataForm.title}}</p><br>
      <span v-html="dataForm.content"></span>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="viewDialog = false">{{$t('groups.determine')}}</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
  import {tableOption} from '@/crud/shop/notice-list'

  export default {
    data () {
      return {
        dataList: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        searchForm: {},
        dateRange: [],
        dataListLoading: false,
        tableOption: tableOption,
        viewDialog: false,
        dataForm: {}
      }
    },
    created () {
    },
    mounted () {
    },
    methods: {
      // 查看单个平台公告
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl('/shop/notice/info/' + this.dataForm.id),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              this.dataForm = data
            })
          }
        })
      },
      // 关闭弹窗
      handleClose (done) {
        done()
        this.viewDialog = false
      },
      getDataList (page) {
        this.$http({
          url: this.$http.adornUrl('/shop/notice/listPage'),
          method: 'get',
          params: this.$http.adornParams(Object.assign({
            current: page == null ? this.page.currentPage : page.currentPage,
            size: page == null ? this.page.pageSize : page.pageSize,
            'beginTime': this.dateRange ? this.dateRange[0] : null, // 开始时间
            'endTime': this.dateRange ? this.dateRange[1] : null // 结束时间
          }, this.searchForm))
        }).then(({data}) => {
          this.dataList = data.records
          this.page.total = data.total
          this.dataListLoading = false
        })
      },
      // 查看
      viewNotice (id) {
        this.viewDialog = true
        this.$nextTick(() => {
          this.init(id)
        })
      },
      // 清空自定义数据
      searchReset () {
        this.dateRange = []
      },
      // 刷新回调用
      refreshChange () {
        this.page = this.$refs.crud.$refs.tablePage.defaultPage
        this.getDataList(this.page)
      },
      searchChange (params) {
        this.searchForm = params
        this.page.currentPage = 1
        this.page.pageSize = 10
        this.getDataList(this.page)
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>

